package com.talkology.pilot.student.controller;

import com.talkology.pilot.database.model.Coupon;
import com.talkology.pilot.student.service.ICouponService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping(value = "/coupon")
public class CouponController {

    @Autowired
    private ICouponService service;


    @RequestMapping(value = "/all", method= RequestMethod.GET)
    @ResponseBody
    public List<Coupon> getCouponByFilter(@RequestParam(value = "useFlag", required = false) Integer useFlag,
                                           @RequestParam(value = "classNum", required = false) Integer classNum) {
        return service.getAllByFilter(useFlag, classNum);
    }

    @RequestMapping(value = "/info", method= RequestMethod.GET)
    @ResponseBody
    public Coupon getInfo(@RequestParam(value = "index", required = true) Integer index) {
        return service.getInfo(index);
    }

    @RequestMapping(value = "/add", method= RequestMethod.PUT)
    @ResponseBody
    public void addCouponInfo(@RequestBody Coupon record) {
        service.add(record);
    }

    @RequestMapping(value = "/update", method= RequestMethod.PUT)
    @ResponseBody
    public void updateCouponInfo(@RequestBody Coupon record) {
        service.edit(record);
    }

    @RequestMapping(value = "/delete", method= RequestMethod.DELETE)
    @ResponseBody
    public void deleteCouponInfo(@RequestParam(value = "index", required = false) Integer index) {
        service.delete(index);
    }
}
